<?php

namespace cms\modules\v1\controllers;

use cms\modules\v1\models\access\ModuleActions;
use cms\modules\v1\models\CommonInfo;
use common\models\Functions;
use yii\filters\auth\HttpHeaderAuth;
use yii\helpers\ArrayHelper;

/**
 * 首页控制器
 * Class HomeController
 * @package cms\modules\v1\controllers
 */
class CommonController extends DefaultController
{

    public $modelClass = 'cms\modules\v1\models\CommonInfo';
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            'authenticator' => [
                'class' =>  HttpHeaderAuth::className(),    //head头部验证
                'header' => 'access-token',
                'optional' => [                     //需要过滤掉不用token参数的方法

                ]
            ]
        ]);
    }

    public function actionList() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (\Yii::$app->request->isGet) {
            return (new CommonInfo())->getList();
        }
    }

    public function actionInfo() {
        $check = (new ModuleActions())->checkActions();
        if ($check !== true) {
            return Functions::formatRestAPI(1, $check);
        }
        if (\Yii::$app->request->isPost) {
            return (new CommonInfo())->saveInfo();
        }
    }

}
